package jsd2204.bookstore.bookserver.utils;

import jsd2204.bookstore.bookserver.BookserverApplication;
import jsd2204.bookstore.bookserver.mapper.DataSimulationMapper;
import jsd2204.bookstore.bookserver.utils.simulationEntity.Money;
import jsd2204.bookstore.bookserver.utils.simulationEntity.Sales;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Random;

/**
 * @author jiale
 * @version 1.0
 * @description这是专门模拟数据的类
 * @date 2022/08/03 08:12
 **/
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = BookserverApplication.class)
public class dataSimulation {
    private Random ran = new Random();
    @Autowired
    DataSimulationMapper mapper;

    @Test
    public void insertMoney() {
        Long max = (long) mapper.selectMax();
        Long id = 1L;
        log.debug("数据库id最大值:" + max);
        while (id <= max) {
            Double money = (double) (ran.nextInt(2000 - 100) + 100);
            Money m = new Money();
            log.debug("书籍id:" + id + ",插入的金额:" + m);
            m.setId(id).setMoney(money);
            mapper.updateBookMoney(m);
            id++;
        }
    }

    @Test
    public void insertSales() {
        Long max = (long) mapper.selectMax();
        Long id = 1L;
        log.debug("数据库id最大值:" + max);
        while (id <= max) {
            Integer sales = (ran.nextInt(5000 - 100) + 100);
            Sales s = new Sales();
            log.debug("书籍id:" + id + ",插入的销量:" + sales);
            s.setId(id).setSales(sales);
            mapper.updateBookSales(s);
            id++;
        }
    }
}
